package top.jiangqiang.qianyi.common.validate;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.dromara.hutool.core.array.ArrayUtil;

public class AllowValidator implements ConstraintValidator<Allow, Object> {
    private String[] allowValues;

    @Override
    public void initialize(Allow constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
        allowValues = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return ArrayUtil.contains(allowValues, String.valueOf(value));
    }
}
